package com.jjh.controller;

import com.jjh.consts.Result;
import com.jjh.pojo.User;
import com.jjh.pojo.vo.LoginUser;
import com.jjh.service.LoginAndRegisterService;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.web.bind.annotation.*;


/**
 * 登录和注册控制器
 */
@RestController
@RequestMapping("/api")

public class LoginAndRegisterController {

    @Resource
    private LoginAndRegisterService loginAndRegisterService;


    @GetMapping("/checkcode")
    public Result getCheckCode(HttpServletRequest request){
        return loginAndRegisterService.getCheckCode(request);
    }



    @PostMapping("/login")
    public Result login(HttpServletRequest request, HttpServletResponse response, @RequestBody LoginUser loginUser){

        return loginAndRegisterService.login(request,response,loginUser);

    }

    /**
     * 退出登录
     * @param username
     * @return
     */
    @GetMapping("/logout")
    public Result logout(String username){
        return loginAndRegisterService.logout(username);
    }




        @GetMapping("/test")
        public Result test(){
         System.out.println("测试....");
         User user = new User();
         user.setUsername("asdfas");
         user.setPassword("312312");
         return Result.ok(user);
        }

//        @GetMapping("/code")
//        public Result getCode(HttpServletRequest request){
//            HttpSession session = request.getSession();
//            Object captcha = session.getAttribute("captcha");
//            return Result.ok(captcha);
//        }







}
